﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ZuesControls.Commons;

namespace ZuesControls.Controls
{
    /// <summary>
    /// 树形列表项
    /// </summary>
    [StyleTypedProperty(Property = "ItemContainerStyle", StyleTargetType = typeof(TreeListViewItem))]
    public class TreeListViewItem : TreeViewItem
    {
        internal double itemTopInTreeSystem; // for virtualization purposes
        internal int hierachyLevel;// for virtualization purposes
        private GridViewRowPresenter PART_Header;
        static TreeListViewItem()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TreeListViewItem), new FrameworkPropertyMetadata(typeof(TreeListViewItem)));
            FrameworkElementFactory vPanel = new FrameworkElementFactory(typeof(VirtualizingTreePanel));
            vPanel.SetValue(VirtualizingTreePanel.IsItemsHostProperty, true);
            ItemsPanelTemplate vPanelTemplate = new ItemsPanelTemplate();
            vPanelTemplate.VisualTree = vPanel;
            ItemsPanelProperty.OverrideMetadata(typeof(TreeListViewItem), new FrameworkPropertyMetadata(vPanelTemplate));
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            PART_Header = this.GetTemplateChild(nameof(PART_Header)) as GridViewRowPresenter;
            if (PART_Header != null)
            {
                int count = VisualTreeHelper.GetChildrenCount(PART_Header);
            }
        }
        public TreeListView ParentTreeView { get; set; }

        /// <inheritdoc/>
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new TreeListViewItem();
        }

        /// <inheritdoc/>
        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return item is TreeListViewItem;
        }
    }
}
